package test;

import static org.junit.Assert.*;

import java.util.ArrayList;

import main.Facade;
import main.FacadeDispatcher;
import main.World;
import movement.Location;

import org.junit.*;

import unit.Garage;
import dispatch.DispatchCenter;
import emergency.*;

public class useCaseTestInspectEmergencies {
	Facade facade;
	Location justALocation;
	
	DispatchCenter center;
	Garage garage;
	
	Emergency em1, em2, em3, em4;
	
	@Before
	public void setUp() throws Exception {
		String args[] = new String[1];
		args[0] = "environment.dat";
		World world = new World(args);
		facade = new FacadeDispatcher(world);
		
		center = facade.getDispatchCenter();
		garage = center.getGarage();
		justALocation = new Location(10,10,"NameDoesn'tMatter");
		
		em1 = new Fire(justALocation, Severity.NORMAL, center, Fire.Size.HOUSE, true, 1, 1);
		em2 = new PublicDisturbance(justALocation, Severity.NORMAL, center, 1);
		em3 = new TrafficAccident(justALocation, Severity.NORMAL, center, 1, 1);
		em4 = new Robbery(justALocation, Severity.NORMAL, center, false, true);
	}
	
	@Test
	public void testInspectEmergencies(){
		ArrayList<Emergency> rec = center.getEmergencyboard().getEmergenciesRecorded();
		assertEquals(4,rec.size());
		ArrayList<Emergency> inprog = center.getEmergencyboard().getEmergenciesInProgress();
		assertEquals(0,inprog.size());
		ArrayList<Emergency> comp = center.getEmergencyboard().getEmergenciesCompleted();
		assertEquals(0,comp.size());
		ArrayList<Emergency> canc = center.getEmergencyboard().getEmergenciesCancelled();
		assertEquals(0,canc.size());
		
		em1.sendUnits();
		
		rec = center.getEmergencyboard().getEmergenciesRecorded();
		assertEquals(3,rec.size());
		inprog = center.getEmergencyboard().getEmergenciesInProgress();
		assertEquals(1,inprog.size());
		comp = center.getEmergencyboard().getEmergenciesCompleted();
		assertEquals(0,comp.size());
		canc = center.getEmergencyboard().getEmergenciesCancelled();
		assertEquals(0,canc.size());
		
		em2.sendUnits();
		
		rec = center.getEmergencyboard().getEmergenciesRecorded();
		assertEquals(2,rec.size());
		inprog = center.getEmergencyboard().getEmergenciesInProgress();
		assertEquals(2,inprog.size());
		comp = center.getEmergencyboard().getEmergenciesCompleted();
		assertEquals(0,comp.size());
		canc = center.getEmergencyboard().getEmergenciesCancelled();
		assertEquals(0,canc.size());
		
		em3.sendUnits();
		
		rec = center.getEmergencyboard().getEmergenciesRecorded();
		assertEquals(1,rec.size());
		inprog = center.getEmergencyboard().getEmergenciesInProgress();
		assertEquals(3,inprog.size());
		comp = center.getEmergencyboard().getEmergenciesCompleted();
		assertEquals(0,comp.size());
		canc = center.getEmergencyboard().getEmergenciesCancelled();
		assertEquals(0,canc.size());
		
		em1.cancelEmergency();
		
		rec = center.getEmergencyboard().getEmergenciesRecorded();
		assertEquals(1,rec.size());
		inprog = center.getEmergencyboard().getEmergenciesInProgress();
		assertEquals(2,inprog.size());
		comp = center.getEmergencyboard().getEmergenciesCompleted();
		assertEquals(0,comp.size());
		canc = center.getEmergencyboard().getEmergenciesCancelled();
		assertEquals(1,canc.size());
		
		em4.sendUnits();
		
		rec = center.getEmergencyboard().getEmergenciesRecorded();
		assertEquals(0,rec.size());
		inprog = center.getEmergencyboard().getEmergenciesInProgress();
		assertEquals(3,inprog.size());
		comp = center.getEmergencyboard().getEmergenciesCompleted();
		assertEquals(0,comp.size());
		canc = center.getEmergencyboard().getEmergenciesCancelled();
		assertEquals(1,canc.size());

		em2.cancelEmergency();
		em3.complete();
		em4.complete();
		
		rec = center.getEmergencyboard().getEmergenciesRecorded();
		assertEquals(0,rec.size());
		inprog = center.getEmergencyboard().getEmergenciesInProgress();
		assertEquals(0,inprog.size());
		comp = center.getEmergencyboard().getEmergenciesCompleted();
		assertEquals(2,comp.size());
		canc = center.getEmergencyboard().getEmergenciesCancelled();
		assertEquals(2,canc.size());
	}
}
